<template>
  <div type="border-card">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-dropdown class="right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <el-button type="primary" plain icon="Plus" size="small">基础结构</el-button>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item
                  v-for="item in OptionList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  @click="createNode(item.value)"
              >{{item.label}}</el-dropdown-item>
              <!--              <el-dropdown-item @click="createNode('vanilla')">香草期权</el-dropdown-item>
                            <el-dropdown-item @click="createNode('digital')">二元期权</el-dropdown-item>
                            <el-dropdown-item @click="createNode('doubleDigital')">双层二元期权</el-dropdown-item>
                            <el-dropdown-item @click="createNode('multiDigital')">三层阶梯期权</el-dropdown-item>
                            <el-dropdown-item @click="createNode('rangeaccrual')">区间累计期权</el-dropdown-item>
                            &lt;!&ndash;                                <el-dropdown-item @click="createNode('touch')">触碰期权</el-dropdown-item>&ndash;&gt;
                            <el-dropdown-item @click="createNode('singleSharkFin')">单鲨期权</el-dropdown-item>-->
              <!--                                <el-dropdown-item @click="createNode('doubleShark')">双鲨期权</el-dropdown-item>-->
              <!--              <el-dropdown-item @click="createNode('basicsnowball')">保本雪球</el-dropdown-item>-->
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-form-item>
      <el-form-item label="计算日期">
        <el-date-picker
            v-model="calcPricingParam.valueDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="定价环境" prop="cfgId">
        <baseCombox url="/pricing/comboBox/queryPriceCfg4Local.action?productType=OtcOption"
                    ref="cfgIdRef"
                    clearable
                    valueField="cfgId"
                    labelField="name" @defaultSelect="(value) => {calcPricingParam.cfgId = value}"
                    :defaultSelectIndex="'0'"
                    size="small"
                    style="width: 240px" placeholder="定价配置" v-model="calcPricingParam.cfgId"></baseCombox>
      </el-form-item>
    </el-form>
    <div style="display: flex; ">
      <div style="max-width:360px;flex:2">
        <!--   期权条款     -->
        <div id='instruments' style="display: inline-flex;margin: 5px 5px 0px 0px;">
          <component :is="getInstrument(instrument.data.optionType)" :useType="'scene'" :calc="submit"
                     :ref="'instrumentRef'+instrument.data.index" :setformData="setformData"
                     :formData="instrument.formData" :del="del"
                     :index="instrument.data.index"
                     :cfgId="instrument.data.cfgId"
                     :getDefaultCfg="getDefaultCfg"
                     :calcPricingParam="instrument.data.calcPricingParam"
                     :valueDate="calcPricingParam.valueDate"
                     :cacheFormData="()=>{}"
                     :result="instrument.data.result"
          />
        </div>
      </div>
      <div style="flex:5; margin: 5px 0px 0px 10px">
        <el-card shadow="always" class="card-header" >
          <template #header>
            <div class="card-header">
              <span>情景参数</span>
            </div>
          </template>
          <div class="param">
            <el-form>

              <div style="display:flex">
                <div style="display:flex;    justify-content: end;flex:4" >
                  <el-form-item class="itemSecene" label="价 格 情 景:" label-width="auto">
                  </el-form-item>
                  <el-form-item class="itemSeceneInner" prop="priceCheck" label="是否偏移" label-width="auto">
                    <el-checkbox size="small" v-model="queryParams.priceCheck"></el-checkbox>
                  </el-form-item>
                </div>
                <div style="flex:6;max-width: fit-content;" >
                  <el-form-item class="itemSeceneInner" prop="priceOffsetType" label="偏移类型" label-width="auto">
                    <DictCombox size="small" :disabled="!queryParams.priceCheck"
                                v-model="queryParams.priceOffsetType"
                                dictType="priceOffsetType" placeholder="类型"></DictCombox>
                  </el-form-item>
                </div>
                <div>
                  <el-form-item class="itemSeceneInner" prop="priceLen" label="步长" label-width="auto">
                    <el-input-number size="small" :disabled="!queryParams.priceCheck"  :precision="stepPrecison1"
                                     v-model="queryParams.priceLen" :min="0"
                                     controls-position="right" placeholder="步长"
                                     label="步长"></el-input-number>
                  </el-form-item>
                </div>
                <div style="flex:7" >
                  <el-form-item class="itemSeceneInner" prop="priceHalf" label="步数" label-width="auto">
                    <el-input-number size="small" :disabled="!queryParams.priceCheck" precision="0"
                                     v-model="queryParams.priceHalf"
                                     :min="1" controls-position="right" placeholder="步数"
                                     label="步数"></el-input-number>
                  </el-form-item>
                </div>

              </div>
              <div style="display:flex">
                <div style="display:flex;flex:4;    justify-content: end;" >
                  <el-form-item class="itemSecene" label="波动率情景:" label-width="auto">
                  </el-form-item>
                  <el-form-item class="itemSeceneInner" prop="volCheck" label="是否偏移" label-width="auto">
                    <el-checkbox size="small" v-model="queryParams.volCheck"></el-checkbox>
                  </el-form-item>
                </div>

                <div style="flex:6;max-width: fit-content;" >
                  <el-form-item :class="'itemSeceneInner'" prop="volType" label="偏移类型" label-width="auto">
                    <DictCombox size="small" :disabled="!queryParams.volCheck" @change="volTypeChg"
                                v-model="queryParams.volType" dictType="percentOffsetType"></DictCombox>
                  </el-form-item>
                </div>
                <div>
                  <el-form-item class="itemSeceneInner" prop="volLen" label="步长" label-width="auto">
                    <el-input-number size="small" :disabled="!queryParams.volCheck" v-model="queryParams.volLen"  :precision="stepPrecison2"
                                     :min="0"
                                     controls-position="right" label="步长"></el-input-number>
                  </el-form-item>
                </div>
                <div style="flex:7" >
                  <el-form-item class="itemSeceneInner" prop="volHalf" label="步数" label-width="auto">
                    <el-input-number size="small" :disabled="!queryParams.volCheck" v-model="queryParams.volHalf"   precision="0"
                                     :min="1"
                                     controls-position="right" label="步数"></el-input-number>
                  </el-form-item>
                </div>
              </div>
            </el-form>
          </div>
          <div class="result">
            <el-tabs tab-position="left" v-show="showFlag" v-model="activeName" type="card">
              <!--动态价值tab页-->
              <!--      <el-tab-pane-->
              <!--          v-for="item in greek"-->
              <!--          :key="item.value"-->
              <!--          :label="item.label"-->
              <!--          :name="item.value"-->
              <!--      >-->
              <!--        <component  :is="getTabInfo(item)" :getActiveName="getActiveName" :getResult="getResult"  />-->
              <!--      </el-tab-pane>-->
              <el-tab-pane name="npv" label="npv">
                <xTable ref="fundanalynpvRef" refId="fundanalynpvRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>


                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"  width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsNpvList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="delta" label="delta">
                <xTable ref="fundanalydeltaRef" refId="fundanalydeltaRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsDeltaList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="deltacash" label="deltacash">
                <xTable ref="fundanalydeltacashRef" refId="fundanalydeltacashRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsDeltaCashList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="gamma" label="gamma">
                <xTable ref="fundanalygammaRef" refId="fundanalygammaRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsGammaList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="gammacash" label="gammacash">
                <xTable ref="fundanalygammacashRef" refId="fundanalygammacashRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsGammaCashList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="theta" label="theta">
                <xTable ref="fundanalythetaRef" refId="fundanalythetaRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsThetaList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="vega" label="vega">
                <xTable ref="fundanalyvegaRef" refId="fundanalyvegaRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsVegaList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <el-tab-pane name="rho" label="rho">
                <xTable ref="fundanalyrhoRef" refId="fundanalyrhoRef" multiple="false" v-loading="loading"
                        :data="fundAnalysisList" border="true" :summary-method="summary" show-summary sum-text="风险均值">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50"></el-table-column>
                    <el-table-column label="标的代码" align="center" prop="uICode" :show-overflow-tooltip="true" width="150"/>
                    <el-table-column label="标的名称" align="center" prop="uName" :show-overflow-tooltip="true" width="200"/>
                    <el-table-column :label="volOffsetTitle" align="right" :formatter="getVolPercent" prop="volRate"
                                     :show-overflow-tooltip="true"   width="180"/>
                    <el-table-column align="right" :formatter="formartEmptyTableP2" v-for="item in fundFieldsRhoList"
                                     :prop="item.valueId"
                                     :label="item.text"
                    ></el-table-column>
                  </template>
                </xTable>
              </el-tab-pane>
              <!-- 异常信息-->
              <el-tab-pane name="errInfo" :label="errTitle">
                <xTable ref="fundanalyerrRef" refId="fundanalyerrRef" multiple="false" v-loading="loading"
                        :data="fundAnaErrList" border="true">
                  <template #columList>
                    <el-table-column label="序号" type="index" width="50">
                    </el-table-column>
                    <el-table-column label="合约编号" align="left" prop="iCode" :show-overflow-tooltip="true" width="220"/>
                    <el-table-column label="异常信息" align="left" prop="errInfo" :show-overflow-tooltip="true"/>
                  </template>
                </xTable>
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script setup>
import xTable from '@/xquant/base/xTable'
import DictCombox from '@/xquant/base/dictCombox'
import {defineAsyncComponent, getCurrentInstance, onMounted, provide, ref, watch} from 'vue'
import {reactive} from 'vue'
import {
  formartFormP4,
  formartFormP2,
  unFormartNumber,
  numberPrecision,
  formartTableWithSymbol
} from '@/utils/numberUtil'
import {calcMarket, calcScene, saveCalcLogs, getDefaultPricingParam, getCalendar} from '@/api/calc/otcOption/calc'
import {insertTrade} from '@/api/trade/otcoptiontrade'
import baseCombox from '@/xquant/base/baseCombox'
import {isNotVoid} from '@/utils/util'
import InputAmount from '@/xquant/base/InputAmount'
import {formartNumber} from '../../../../utils/numberUtil'
import {getOptionList,getInstrument} from "@/views/calc/otcOtion/instrument/common/common";
const OptionList = ref([])
const screenHeight = ref(document.documentElement.clientHeight - 120 + 'px')
const {proxy} = getCurrentInstance()
const fundAnalysisList = ref([])
const fundAnaErrList = ref([])
const loading = ref(false)
const stepPrecison1=ref(2);
const stepPrecison2=ref(3);
//希腊字母field
const fundFieldsNpvList = ref([])
const fundFieldsDeltaList = ref([])
const fundFieldsDeltaCashList = ref([])
const fundFieldsGammaList = ref([])
const fundFieldsGammaCashList = ref([])
const fundFieldsThetaList = ref([])
const fundFieldsVegaList = ref([])
const fundFieldsRhoList = ref([])
const showFlag=ref(true);
const errTitle = ref('异常信息')
const volOffsetTitle = ref('波动率偏移(绝对(%)\\价格')
const activeName = ref('npv')
let instrument = reactive({
  data: {}
})
const tableData = reactive({
  volArr: [],
  spotPriceArr: [],
  volObject: {},
  volObjectLength: 0,
  data: []
})

let index = 0
const calcPricingParam = reactive({
  valueDate: proxy.$moment(new Date()).format('YYYY-MM-DD'),
  cfgId: '',
})
const createNode = (optionType) => {
  var ele = {
    index: 0,
    optionType: optionType,
    calcPricingParam: {},
    result: {},
    cfgId: calcPricingParam.cfgId
  }
  ele.index = index
  instrument.data = ele
  window.dispatchEvent(new Event('resize')) // 触发window的resize事件
  index++
  tableData.volObjectLength = 0
  tableData.data.length = 0
}


watch(() => calcPricingParam.cfgId, (nv, ov) => {
  if (nv != ov) {
    instrument.data.cfgId = nv
  }
})
const getDefaultCfg = (optionJson, index) => {
  if (optionJson.instrument.termsheet.underlyerIds.length > 0 && optionJson.instrument.termsheet.underlyerIds[0] != '') {
    getDefaultPricingParam(optionJson).then(response => {
      if (response.errorCode == -1) {

      } else {
        let {underlyingPricingParams, discount, calcPPCode} = response.result.calcPricingParam
        let {spotQuoteType, dividend, volSurface} = underlyingPricingParams[0]
        let ppcfg = {
          calcPPCode: calcPPCode,
          spotQuoteType: spotQuoteType,
          dividend: dividend,
          discount: discount,
          volSurface: volSurface
        }
        instrument.data.calcPricingParam = ppcfg
        return response.result.calcPricingParam
      }
    })
  }
}

function submit(otcOption) {
  let param = {
    'accId': queryParams.value.accId,
    'underlyerId': queryParams.value.underlyerId,
    'cfgId': queryParams.value.cfgId,
    'priceType': queryParams.value.priceType,
    'success': true
  }
  if (queryParams.value.priceCheck) {
    let stepLength = queryParams.value.priceLen
    if (queryParams.value.priceOffsetType == '0') {
      stepLength = stepLength / 100
    }
    param = proxy.lsh.assign(param, {
      'priceScene': JSON.stringify({
        'type': queryParams.value.priceOffsetType,
        'stepLength': stepLength,
        'stepSize': queryParams.value.priceHalf
      })
    })
  }
  if (queryParams.value.volCheck) {
    let stepLength = queryParams.value.volLen / 100
    param = proxy.lsh.assign(param, {
      'volScene': JSON.stringify({
        'type': queryParams.value.volType,
        'stepLength': stepLength,
        'stepSize': queryParams.value.volHalf
      })
    })
  }
  //处理情景因子
  param = proxy.lsh.assign(otcOption, {'calcSceneParams': getSceneParam(param)})
  calcScene(param).then((response) => {
    if (response.errorCode != '-1') {
      activeName.value = 'npv'
      fundAnaErrList.value = response.msg.error
      getFieldsList(response.msg.fields)
      errTitle.value = '异常信息(' + response.msg.error.length + ')'
      loading.value = false
      fundAnalysisList.value = response.msg.success
      proxy.$modal.msgSuccess('计算成功！')
    } else {
      proxy.$modal.msgSuccess('计算失败！')
    }
  })
}
function getFieldsList(result) {

  let tmpNpvList = []
  let tmpDeltaList = []
  let tmpDeltaCashList = []
  let tmpGammaList = []
  let tmpGammaCashList = []
  let tmpThetaList = []
  let tmpVegaList = []
  let tmpRhoList = []
  for (let i = 0; i < result.length; i++) {
    if (result[i].indexOf('#') > -1 && result[i].split('#').length > 3) {
      if (result[i].split('#')[3] == 'npv') {
        tmpNpvList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'delta') {
        tmpDeltaList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'deltaCash') {
        tmpDeltaCashList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'gamma') {
        tmpGammaList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'gammaCash') {
        tmpGammaCashList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'theta') {
        tmpThetaList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'vega') {
        tmpVegaList.push(getData(result[i]))
      } else if (result[i].split('#')[3] == 'rho') {
        tmpRhoList.push(getData(result[i]))
      }
    }
  }
  fundFieldsNpvList.value = tmpNpvList
  fundFieldsDeltaList.value = tmpDeltaList
  fundFieldsDeltaCashList.value = tmpDeltaCashList
  fundFieldsGammaList.value = tmpGammaList
  fundFieldsGammaCashList.value = tmpGammaCashList
  fundFieldsThetaList.value = tmpThetaList
  fundFieldsVegaList.value = tmpVegaList
  fundFieldsRhoList.value = tmpRhoList
}

function getData(result) {
  return {
    'tabId': result.split('#')[3],
    'text': formartNumber(Number(result.split('#')[1].replace('_', '.')), 2),
    'valueId': result
  }
}
function getVolPercent(row, column, cellValue) {
  return proxy.lsh.round(proxy.lsh.add(Number(cellValue), 0) * 100, 3) + '%'
}
function del(current) {
  instrument.data = {}
}

const search = ref('')
const filterTableData = computed(() =>
    tableData.filter(
        (data) =>
            !search.value ||
            data.name.toLowerCase().includes(search.value.toLowerCase())
    )
)
const handleEdit = (index, row) => {
  // console.log(index, row)
}
const handleDelete = (index, row) => {
  // console.log(index, row)
}

const data = reactive({
  queryParams: {
    groupId: undefined,
    underlyerId: undefined,
    priceType: 'DP_CLOSE',
    // aTypes:['0','2'],
    cfgId: '',
    priceCheck: true,
    priceOffsetType: '0',
    priceLen: 2,
    priceHalf: 2,
    volCheck: true,
    volType: '1',
    volLen: 2,
    volHalf: 2

  },
  rules: {
    groupId: [{required: false, trigger: 'blur'}],
    underlyerId: [{required: true, message: '挂钩标的不能为空', trigger: 'blur'}],
    aTypes: [{required: false, trigger: 'blur'}],
    priceType: [{required: true, message: '价格类型不能为空', trigger: 'blur'}],
    cfgId: [{required: true, message: '定价配置不能为空', trigger: 'blur'}],
    priceOffsetType: [{required: true, message: '价格偏移类型不能为空', trigger: 'blur'}],
    priceLen: [{required: true, message: '价格偏移步长不能为空', trigger: 'blur'}],
    priceHalf: [{required: true, message: '价格偏移步数不能为空', trigger: 'blur'}],
    volType: [{required: true, message: '波动率偏移不能为空', trigger: 'blur'}],
    volLen: [{required: true, message: '波动率偏移步长不能为空', trigger: 'blur'}],
    volHalf: [{required: true, message: '波动率偏移步数不能为空', trigger: 'blur'}]
  }
})

const {queryParams, rules} = toRefs(data)

function getSceneParam(param) {
  let sceneParam = []
  // 价格因子
  let chkScenePrice = queryParams.value.priceCheck
  let priceLen = 0
  let priceHalf = 0
  let priceType = 1
  if (chkScenePrice) {
    priceType = queryParams.value.priceOffsetType
    priceLen = queryParams.value.priceLen
    if (priceType == '0') {
      priceLen = priceLen / 100
    }
    priceHalf = Number.parseInt(queryParams.value.priceHalf) / 2
  }
  // 波动率因子
  var chkSceneVol = queryParams.value.volCheck
  var volLen = 0
  var volHalf = 0
  var volType = 1
  if (chkSceneVol) {
    volType = queryParams.value.volType
    volLen = queryParams.value.volLen / 100
    volHalf = queryParams.value.volHalf / 2
  }
  var sceneIndex = 0
  for (var i = -priceHalf; i <= priceHalf; i++) {
    var spotPriceInc = null
    if (priceHalf != 0) {
      spotPriceInc = {
        type: priceType,
        value: i * priceLen
      }
    }
    for (var j = -volHalf; j <= volHalf; j++) {
      var volSurfaceInc = null
      if (volHalf != 0) {
        volSurfaceInc = {
          type: volType,
          value: j * volLen
        }
      }
      sceneIndex++
      var sceneItem = {
        sceneID: 'scene' + sceneIndex,
        underlyingSceneParams: [{}]
      }
      if (spotPriceInc != null) {
        sceneItem.underlyingSceneParams[0].spotPriceInc = spotPriceInc
      }
      if (volSurfaceInc != null) {
        sceneItem.underlyingSceneParams[0].volSurfaceInc = volSurfaceInc
      }
      sceneParam.push(sceneItem)
    }
  }
  return sceneParam
}

function summary(param) {
  return proxy.columnsCal(param, '风险均值', 2, 3, null, 2, '2')
}

function volTypeChg(newVal) {
  let iTitle = queryParams.value.volType == 1 ? '绝对%' : '相对%'
  volOffsetTitle.value = '波动率偏移(' + iTitle + ')\\价格'
}
onMounted(()=>{
  getOptionList().then(res=>{
    OptionList.value = res;
  });
})
/**/
const getIndexRef = (index)=>{

  return proxy.$refs['instrumentRef'+index]
}
provide('getIndexRef',getIndexRef)

</script>
<style scoped>
.result {
  padding: 5px;
}

.param {
  padding: 5px;
}

/deep/ .itemSecene .el-form-item__label {
  color: #686868;
  font-weight: 550;
}

/deep/ .itemSeceneInner .el-form-item__label {
  color: #686868;
  font-weight: 550;
}
/deep/ .el-tabs__item:nth-child(2){
  padding-left: 8px !important;
}
</style>
